home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 10
/
FM Towns Free Software Collection 10.iso
/
ms_dos
/
tool
/
fapxtool
/
src
/
txl
/
txllog.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-12
|
9KB
|
395 lines
/***************
*
* g:\exe\txl\src\txllog.c
*/
#include "txl.h"
#define BYTE(x) *((unsigned char *)(x))
#define bit_chk(x,f) ((int)(BYTE(x+(f/8)) >> 7-f%8) & 1)
void logfindstr(FILE *input)
{
long cline = 1;
int k, style, falseflg = 0x0000;/* cnt = 0;*/
char *mes_buf, *serchmax;
#if 0
char **pftbl = &pfstr[0];
#endif
mes_buf = malloc(30000);
serchmax = mes_buf+28000;
if (mes_buf == NULL){
errexit("out of memory(-log)");
}
fread(mes_buf, 1, 1999, input);
log_bufptr = mes_buf;
while ((*log_bufptr != 0x0ff) && (cline < log_tline)) {
fread((mes_buf + 1999), 1, 28000, input);
while ((cline < log_tline) && (cline == 1)) {
for (k = 0; k < MAX_STR; k++) {
if ((*pfstr[k] == *log_bufptr) || (*pfstr[k] == '*')) {
pfstr[k]++;
}
else {
pfstr[k] = sfstr[k];
}
}
if (*pfstr[0]==NUL) get_forum(1);
if (*pfstr[1]==NUL) get_forum(2);
if (*pfstr[2]==NUL) get_forum(2);
if (*pfstr[3]==NUL) get_libno(1);
if (*pfstr[4]==NUL) get_libno(2);
if (*pfstr[5]==NUL) {
strncpy(log_idstr,log_bufptr+1,8); /* HPログ */
}
if (*pfstr[6]==NUL) strncpy(log_idstr,log_bufptr+1,8); /* catlog */
if ((*pfstr[7] == NUL) || (*pfstr[8] == NUL)) { /* パティオ */
strncpy(log_pname,log_bufptr+1, 8);
log_fname[0] = NUL;
}
if (*log_bufptr == 0x0a) cline++;
log_bufptr++;
}
while ((cline < log_tline) && (log_bufptr < serchmax)) {
for (k = 0; k < MAX_STR; k++) {
if ((*pfstr[k] == *log_bufptr) || (*pfstr[k] == '*')) {
pfstr[k]++;
}
else {
pfstr[k] = sfstr[k];
falseflg |= (1 << k);
}
}
if (*pfstr[0]==NUL) get_forum(1);
else if (*pfstr[1]==NUL) get_forum(2);
else if (*pfstr[2]==NUL) get_forum(2);
else if (*pfstr[3]==NUL) get_libno(1);
else if (*pfstr[4]==NUL) get_libno(2);
else if (*pfstr[5]==NUL) {
strncpy(log_idstr,log_bufptr+1,8); /* HPログ */
cline++;
}
else if (*pfstr[6]==NUL) strncpy(log_idstr,log_bufptr+1,8);
/* ↑catlog */
else if ((*pfstr[7] == NUL) || (*pfstr[8] == NUL)) {/* パティオ */
strncpy(log_pname,log_bufptr+1, 8);
log_fname[0] = NUL;
if (*pfstr[7] == NUL) {
cline++;
}
}
if (falseflg == 0x1ff) {
while (*log_bufptr != 0x0a) {
log_bufptr++;
}
falseflg = 0x0000;
cline++;
}
log_bufptr++;
/* if (*log_bufptr == 0x0a) cline++; */
}
/* ↓パフォーマンスは落ちるかもしれない */
while (kbhit()) {
if (getch() == 27) {
fprintf(fpmes, "TXF:abort request.\n");
free(mes_buf);
Exit(1);
}
}
if (cline < log_tline) {
/* strncpy(mes_buf, log_bufptr, 1999); */
strncpy(mes_buf, mes_buf + 28000, 1999);
log_bufptr -= 28000;
}
}
if (cline == log_tline) {
style = linestyle();
switch (style) {
case 1: /* 会議室一覧 */
case 2: /* 会議室の境目 */
case 3: /* ストック会議室発言の題名 */
case 8: /* サイクリック会議室発言の題名/パティオの発言題名 */
meschk(style);
break;
case 4: /* データライブラリ一覧 */
case 5: /* 週間FTOWNS */
case 19:/* 引用1(引用文字半角) */
case 20:/* 引用2(引用文字全角) */
dlibchk(style);
break;
case 18:
fgalchk();
break;
case 6: /* hpの題名 */
hpchk();
break;
case 7: /* mailの題名 */
case 13: /* newmailの題名 */
case 10: /* from PC-VAN */
case 15: /* from PC-VAN newmail */
mailchk(style);
break;
#if 0
case 9: /* FFMのデータライブラリ インフォメーション */
ffmtopchk();
break;
#endif
case 12:
fravtopchk();
break;
case 11:
case 16:
widegatechk();
break;
case 14:
ffsutopchk(style);
break;
case 17:
maillistchk();
break;
default:
fprintf(fpmes, "Error:unknown line style");
fclose(input);
free(mes_buf);
Exit(1);
}
}
else {
fprintf(fpmes, "Error:find EOF before target line");
fclose(input);
}
free(mes_buf);
}
void logs()
{
FILE *input = NULL;
if (inputfile != NULL) input = fopen(inputfile, "rb");
if (input == NULL) {
fprintf(fpmes, "Error:cannot open input file '%s'\n", inputfile);
Exit(0);
}
logfindstr(input);
fclose(input);
}
void loginit()
{
int i;
fprintf(stderr, "TXL: open LOGCHECK\n");
for (i = 0; i < MAX_STR; i++) {
pfstr[i] = sfstr[i];
}
*log_handle = NUL;
log_hpstyle = -1;
log_hpchr = 0;
}
void logdriver(char *val[])
{
int i=0;
loginit();
for (i = 0; val[i] != NULL; i++) {
if (val[i][0] == '-') {
switch (val[i][1]) {
case 'i':
case 'I':
if (val[i+1][0] != '-') inputfile = val[i+1];
else i--;
break;
case 'l':
case 'L':
if (val[i+1][0] != '-') log_tline = atol(val[i+1]);
else i--;
case 's':
case 'S':
if (val[i+1] != NULL) strncpy(log_resstr, val[i+1], 15);
break;
case 'H':
log_hpstyle++;
case 'h':
log_hpstyle++;
if (val[i][2] != NUL) {
log_hpchr = (unsigned char)val[i][2];
if (val[i][3] != NUL) {
log_hpchr = (log_hpchr << 8) | (unsigned char)val[i][3];
}
}
if (val[i+1] != NULL) strncpy(log_handle, val[i+1], 16);
break;
default:
fprintf(fpmes, "Error:invailed parameter'%s'\n", val[i]);
Exit(1);
}
i++;
}
else if (inputfile == NULL) {
inputfile = val[i];
}
else if ((inputfile != NULL) && (log_tline == 0)) {
log_tline = atol(val[i]);
}
else if ((inputfile != NULL) && (log_tline != 0) && (*log_resstr == NUL)) {
strncpy(log_resstr,val[i], 15);
}
else if ((inputfile != NULL) && (log_tline != 0) && (*log_resstr != NUL)) {
strncpy(log_handle, val[i], 16);
}
}
logs();
Exit(0);
}
int matchstr(char *form, char far *txtptr)
{
char far *logtmp;
char *strtmp;
int i, trueflg = 0, count = 0;
logtmp = txtptr;
strtmp = form;
/* while ((*strtmp != NUL) && (*logtmp != 0x0a)) { */
while (*strtmp != NUL) {
trueflg = FALSE;
switch (*strtmp) {
case '%':
if (isdigit(*logtmp) || (*logtmp == ' ')) {
trueflg = TRUE;
}
break;
case '*':
if (isalpha(*logtmp)) {
trueflg = TRUE;
}
break;
case '&':
if (isalpha(*logtmp) || isdigit(*logtmp)) {
trueflg = TRUE;
}
break;
case '_':
if (*logtmp == ' ') {
trueflg = TRUE;
}
break;
case '$':
trueflg = TRUE;
break;
case 0x27:
strtmp++;
if (*logtmp == *strtmp) {
trueflg = TRUE;
}
break;
case '^':
strtmp++;
count = ((*strtmp) - ('0'));
strtmp++;
while (trueflg != TRUE) {
for (i = 0; i < count; i++) {
if ((*(logtmp + i) != *(strtmp + i)) || (*(logtmp + i) == 0x0d)) {
break;
}
}
if (i != count) {
logtmp++;
if (*logtmp == 0x0a) {
break;
}
}
else {
trueflg = TRUE;
}
}
break;
default:
if (islower(*strtmp)) {
if (tolower(*logtmp) == *strtmp) {
trueflg = TRUE;
}
}
else {
if (*logtmp == *strtmp) {
trueflg = TRUE;
}
}
}
/* fprintf(stdout, "matchstr:%c,%c:", *strtmp, *logtmp); */
if (trueflg != TRUE) {
/* puts("NG!"); */
return (FALSE);
}
/* puts("GOOD!"); */
strtmp++;
logtmp++;
}
return (TRUE);
}
int linestyle()
{
/*
char logstr_mes1[30]="%% %%%%% ( %%%) %%/%% ";
char logstr_mes2[15]="- ^1 MES(%%):";
char logstr_mes3[41]="%%%/%%% ***%%%%% $$$$$$$$$$$$$$$$ ";
char logstr_mes4[42]="%%%%%/%%%%% ***%%%%% $$$$$$$$$$$$$$$$ ";
char logstr_dlib[42]="%%%%$ ***%%%%% %%/%%/%% %%%%%%% %%%% * ";
char logstr_hp[40]="%%% [%%/%%/%% %%:%%] ***%%%%% ";
char logstr_mail[44]="%% $$$$$$$$$$$$$$$$$ ***%%%%% %%/%% %%:%%";
char logstr_ffmtop[22]="%%/%%[^1]^3(DL%%-%%%)";
char logstr_pcvm[44]="%% - PCV>***%%%%% %%/%% %%:%%";
char logstr_wide[44]="%% WIDE GATE ***%%%%% %%/%% %%:%%";
char logstr_wftowns[5]=" #%";
*/
/*
*(log_bufptr + 80) = NUL;
puts(log_bufptr);
*/
if (matchstr(logstr_mes1, log_bufptr)) return (1);
if (matchstr(logstr_mes2, log_bufptr)) return (2);
if (matchstr(logstr_mes3, log_bufptr)) return (3);
if (matchstr(logstr_dlib, log_bufptr)) return (4);
if (matchstr(logstr_hp, log_bufptr)) return (6);
if (matchstr(logstr_mes4, log_bufptr)) return (8);
if (matchstr(logstr_pcvm2, log_bufptr)) return (15);
if (matchstr(logstr_wide2, log_bufptr)) return (16);
if (matchstr(logstr_mail2, log_bufptr)) return (13);
if (matchstr(logstr_wftowns, log_bufptr)) return (5);
#if 0
if (matchstr(logstr_ffmtop, log_bufptr)) return (9);
#endif
if (matchstr(logstr_fravtop, log_bufptr)) return (12);
if (matchstr(logstr_ffsutop, log_bufptr)) return (14);
if (matchstr(logstr_mlist, log_bufptr)) return (17);
if (matchstr(logstr_qlib, log_bufptr+1)) return (19);
if (matchstr(logstr_qlib, log_bufptr+2)) return (20);
if (matchstr(logstr_fgallib, log_bufptr)) return (18);
if (matchstr(logstr_pcvm, log_bufptr)) return (10);
if (matchstr(logstr_wide, log_bufptr)) return (11);
if (matchstr(logstr_mail, log_bufptr)) return (7);
return (0);
}